/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.route.system.session;

import com.route.system.entity.RpsRouteDescription;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author neco
 */
@Stateless
public class RpsRouteDescriptionFacade extends AbstractFacade<RpsRouteDescription> {
    @PersistenceContext(unitName = persistenceUnitName)
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RpsRouteDescriptionFacade() {
        super(RpsRouteDescription.class);
    }
    public List<RpsRouteDescription> complete(String value) {
        Query query = getEntityManager().createNamedQuery("RpsRouteDescription.findByCompleteValue", RpsRouteDescription.class);
        query.setParameter("descriptionVehicleName", value);
        query.setParameter("stationName", value);
        
        return query.getResultList();
    }
    public RpsRouteDescription findByDescriptionVehicleName(String value) {
        Query query = getEntityManager().createNamedQuery("RpsRouteDescription.findByDescriptionVehicleNameEnd", RpsRouteDescription.class);
        query.setParameter("descriptionVehicleName", value);
        if(!query.getResultList().isEmpty()) {
            return (RpsRouteDescription) query.getResultList().get(0);
        }        
        return null;
    }
    
}
